#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 5e3+5;
const LL MOD = 998244353;

pair<int, int> dat[N];
int n;

int cmp(const pair<int, int> &a, const pair<int, int> &b) {
    return (a.first + a.second) < (b.first + b.second);
}

int x[N][N];

LL inv[N];

LL f[N], invf[N];

LL bin(LL a, LL b, LL p = MOD) {
    LL res = 1;
    for (a%=p; b; b>>=1, a=a*a%p)
        if (b & 1)
            res = res * a % p;
    return res;
}

LL sum1(int x) {
    return 1LL * x * (x+1) / 2  %MOD;
}

int main(int argc, char const *argv[])
{
    f[0] = invf[0] = 1;
    for (int i=1; i<N; ++i) f[i] = f[i-1] * i % MOD;
    invf[N-1] = bin(f[N-1], MOD-2);
    for (int i=N-2; i>=1; --i) {
        invf[i] = invf[i+1] * (i+1) % MOD;
    }
    scanf("%d", &n);
    for (int i=0; i<n; ++i)
        scanf("%d%d", &dat[i].first, &dat[i].second);
    sort(dat, dat+n, cmp);

    for (int i=0; i<n; ++i)
        inv[i] = bin(dat[i].second - dat[i].first + 1, MOD-2, MOD);

    for (int i=0; i<n; ++i) {
        for (int j=i+1; j<n; ++j) {
            x[i][j] = 0;
            if (dat[i].second > dat[j].first) x[i][j] = (sum1(dat[i].second - max(dat[j].first, dat[i].first)) + 1LL * (dat[i].second - dat[i].first + 1) * max(0, dat[i].first - dat[j].first) % MOD) % MOD;
            if (dat[i].second > dat[j].second + 1) x[i][j] = (x[i][j] + MOD - sum1(dat[i].second - dat[j].second - 1)) % MOD;
        }
            
    }

    LL P = 1, ans = 0;
    for (int i=0; i<n; ++i)
        P = P * (dat[i].second - dat[i].first + 1) % MOD;
    for (int i=0; i<n; ++i) {
        LL PP = P * inv[i] % MOD;
        for (int j=0; j<i; ++j) {
            ans = (ans + PP * inv[j] % MOD * x[j][i]) % MOD;
        }
    }
    LL B = 1;
    // printf("%lld\n", ans);
    for (int i=0; i<n; ++i)
        B = B * inv[i] % MOD;
    ans = ans * B % MOD;
    printf("%lld\n", ans);
    

    return 0;
}
